<?php
/*
	DbConnect.class
	@author Shawn Haworth
	@date 2006-04-23

	Quick Reference
  //Set up all paramaters for the connection
  $db = new DbConnect($error_reporting=false,$persistent=false);
  
   //Open the connection to the database
   $db->open() or die($db->error());
 
   //Query the database now the connection has been made
   $db->query("SELECT * FROM....") or die($db->error());

       while($row=$db->fetcharray()) {
       
         //do some stuff
         
       }
       
       //close your connection
       $db->close();
    --------------------------------------------------  
      
       */ 
Class DbConnect {
            
  /* We'll set these here for security puroses, we can also set them all in the constructor if necessary */
  //Take care to taylor your user's privileges to only edit the tables you want them to edit, this will provide increased security
  //The user must be able to create and alter tables that they create for this framework to function properly
  var $host = DATABASE_HOST;
  var $user = DATABASE_USER;
  var $password = DATABASE_PASS;
  var $database = DATABASE_NAME;
  var $persistent = false;
  
  var $conn = NULL;
  
  var $result= false;
  var $error_reporting = false;

  function DbConnect ($error_reporting=true, $persistent=false) { 

	$this->persistent = $persistent;
	$this->error_reporting = $error_reporting;
  }
   
      function open() {
	  
		  if ($this->persistent) {
			    
			$func = 'mysql_pconnect';
		  
		  } else { 
		       
		     $func = 'mysql_connect';
		     
		  }            
		  
		  /* Connect to the MySQl Server */
		  
		  $this->conn = $func($this->host, $this->user, $this->password);
		  
		   if (!$this->conn) {

		       return false;
		   
		   }
		  
		   /* Select the requested DB */
		   
		   if (@!mysql_select_db($this->database, $this->conn)) {
		       
		       return false;
		   }
		     return true;
      } 

      /*close the connection */
      
       function close() {
	      
	   return (@mysql_close($this->conn));
       }

	/* report error if error_reporting set to true */
                
      function error() {
            
          if ($this->error_reporting) { 
                
              return (mysql_error()) ;
          } 
           
      }
     
	function query($sql) {
	       
	     $this->result = @mysql_query($sql, $this->conn);
	
	     return($this->result != false);
	
	}
	function affectedrows() {
	
		return(@mysql_affected_rows($this->conn));
	}

	function numrows() {
	
		return(@mysql_num_rows($this->result));
	
	}
	function fetchobject() {
	
		return(@mysql_fetch_object($this->result, MYSQL_ASSOC));
	
	}
	function fetcharray() {
	
		return(mysql_fetch_array($this->result));
	
	}
	function fetchrow() {
		return(mysql_fetch_row($this->result));
	}
	function fetchassoc() {
	
		return(@mysql_fetch_assoc($this->result));
	}
	
	function freeresult() {
	
		return(@mysql_free_result($this->result));
	
	}

   }
?>
